{// 加载头部公共文件 }
<include file="Public:header" />
<script>

$(function(){
	var roomdialog=$("#roomDialog");
	$("#add").on("click",function(){
		roomdialog.modal("show");	
	})
	$("#close").on("click",function(){
		$("[type='text'],[type='hidden'],textarea,[type='file']").val("");
		roomdialog.modal("hide");	
	})
	$(".roomedit").on("click",function(){
		var $rid=$(this).attr("data-rid");
		var $intro=$(this).attr("data-intro");
		var $name=$(this).attr("data-name");
		var $img=$(this).attr("data-img");
		var $state=$(this).attr("data-state");
		var $delayed=$(this).attr("data-delayed");
		$("#rid").val($rid);
		$("#name").val($name);
		$("#intro").val($intro);
		$("#state").val($state);
		$("#delayed").val($delayed);
		roomdialog.find("h4").text("编辑科室");
		$("#src").empty();
		if($img!=""){
			//$("#src").empty().append($("<a/>").attr("href","__PUBLIC__/"+$img).text($img)).append("<a href=\"#\" class=\"btn btn-primary btn-xs \"><i class=\"glyphicon glyphicon-trash\"></i></a>");
			$("#src").empty().append($("<a/>").attr("href","__PUBLIC__/"+$img).text($img));
		}
		roomdialog.modal("show").find(".help-inline").html("");
	});	
	$(".roomdelete").on("click",function(){
		if(confirm("确定要删除这个科室吗？该科室下的所有医生和预约记录将被一并删除！")){
			$.ajax({
				url:$(this).attr("data-url"),type:"get",dataType:"json",cache:false
			}).done(function(data){
				if(data.status==1){
					location.reload();
				}else{
					alert(data.info);
					return false;
				}
			})
		}
	})
})
</script>
<div class="container">
	<button type="button" class="btn btn-primary navbar-btn" id="add">新增</button>

	<table class="table table-striped">
		<tr>
			<th>科室名称</th><th>预约</th><th>医生</th><th>状态</th><th>操作</th>
		</tr>
		<volist name="list" id="vo">
		<tr>
			<td>{$vo.name}</td>
			<td><a href="{:U('admin/appoint/index/',array('rid'=>$vo['rid']))}">查看</a></td>
			<td><a href="{:U('admin/doctor/index/',array('rid'=>$vo['rid']))}">查看</a></td>	
			<td>{$vo['state']|getRoomState}</td>
			<td><a href="#" data-rid="{$vo.rid}" data-intro="{$vo.intro}" data-img="{$vo.img}" data-state="{$vo.state}" data-name="{$vo.name}" data-delayed="{$vo.delayed}"  class="btn btn-primary btn-xs roomedit">编辑</a>&nbsp; <a href="#" data-url="{:U('admin/room/delete/',array('rid'=>$vo['rid']))}" class="btn btn-danger btn-xs roomdelete">删除</a></td>
		</tr>
		</volist>
	</table>
	
	<ul class="pagination">{$page}</ul>
</div> <!-- /container -->

<!-- channelResDialog start -->
<div id="roomDialog" class="modal" tabindex="-1">
	<div class="modal-dialog" style="width: 500px;">
		<div class="modal-content">
			<div class="modal-header">
				<h4>新增科室</h4>
			</div>
			<form class="form-horizontal" role="form" action="{:U('admin/room/add/')}" method="post" enctype="multipart/form-data">
			<div class="modal-body">
				<input type="hidden" value="" id="rid" name="rid">
					<div class="form-group">
						<label class="col-xs-3 control-label">科室名称</label>
						<div class="col-xs-9">
							<input id="name" name="name" type="text" class="form-control" required autofocus>
							<span class="help-inline"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">延后预约</label>
						<div class="col-xs-9">
							<input id="delayed" name="delayed" type="text" class="form-control" value="0" required autofocus>
							<span class="help-inline"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">状态</label>
						<div class="col-xs-9">
							<select id="state" name="state">
								<option value="0">正常</option>
								<option value="1">停用</option>
							</select> 
							<span class="help-inline"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">科室图片</label>
						<div class="col-xs-9">
							<input id="img" name="img" type="file" class="form-control">
							<div id="src"></div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">科室介绍</label>
						<div class="col-xs-9">
							<textarea class="form-control" id="intro" name="intro" rows="3"></textarea>
						</div>
					</div>
			</div>
			<div class="modal-footer">
				<a class="btn btn-default" href="#" id="close">取消</a>
				<input class="btn btn-primary" type="submit" value="确认"/>
			</div>
			</form>
		</div>
	</div>
</div>
<!-- channelResDialog end -->

<!-- 主页面结束 -->
{// 加载尾部公共文件 }
<include file="Public:footer" />